package java5.enumeration;

public enum ErrorCodeEnum {
  OK(0, ""),
  UNKOWN_ERROR(-1, "未知错误"),
  INVOKE_FAILED(1, "调用服务异常"),
  PARSE_FAILED(3, "解析报文异常"),
  SERIALIZE_ERROR(4, "序列化报文异常"),
  IO_EXCEPTION(5, "IO异常"),
  CLIENT_ERROR(6, "客户端错误"),
  SERVER_ERROR(7, "服务端错误"),
  NOT_ALLOWED(8, "不允许访问该服务/接口"),
  NO_RESULT_CODE(9, "缺少错误代码"),

  NO_SUCH_SERVICE(11, "服务不存在"),
  NOT_AVAILABLE(12, "服务器不可用，被熔断也会报此问题"),
  NO_SUCH_METHOD(13, "接口不存在"),
  NOT_IMPLEMENTED(14, "接口未实现"),
  INVALID_CLIENT(15, "非法的客户端"),
  INVALID_DESCRIPTOR(16, "非法的接口描述信息"),
  NOT_SUPPORTED_CONTENT_TYPE(17, "不支持的Content-Type"),
  CONNECTION_FAILURE(18, "连接失败"),
  CONNECTION_CLOSED(19, "连接关闭"),
  NOT_SUPPORTED_ACCEPT(20, "不支持的accept"),

  FLOW_CONTROLLED(21, "流量控制"),
  AUTHENTICATION_REQUIRED(22, "需要提供鉴权信息"),
  AUTHENTICATION_FAILED(23, "鉴权错误"),
  JAVA_EXCEPTION(24, "服务端执行代码时抛出java异常"),

  EXECUTE_TIMEOUT(51, "执行超时"),
  CLIENT_TIMEOUT(52, "客户端超时"),
  THREAD_INTERRUPTED(53, "线程被中断"),
  EXECUTION_ERROR(54, "执行异常"),
  EVENTBUS_ERROR(55, "event bus 线程执行超时"),
  SERVER_BUSY(56, "服务端忙碌"),
  SERVER_TIMEOUT(58, "服务执行超时");

  private int code;
  private String message;

  ErrorCodeEnum(int code, String message) {
    this.code = code;
    this.message = message;
  }

  public static String getMessageByCode(int code) {
    for (ErrorCodeEnum value : values()) {
      if (value.code == code) {
        return value.message;
      }
    }
    return "";
  }

  public int getCode() {
    return code;
  }

  public String getMessage() {
    return message;
  }

}
